#ifndef IMAGEUPLOADER_H
#define IMAGEUPLOADER_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QJsonObject>
#include <QJsonDocument>

class ImageUploader : public QObject
{
    Q_OBJECT
public:
    explicit ImageUploader(QObject *parent = nullptr);

    void uploadImage(const QString &table, const QByteArray &imageData, const QString &suffix = "jpg");

    QString lastUrl() const { return m_lastUrl; }
    QString lastError() const { return m_lastError; }

signals:
    void uploadFinished(const QString &url);
    void uploadFailed(const QString &error);

private slots:
    void onUploadFinished(QNetworkReply *reply);

private:
    QNetworkAccessManager *m_manager;
    QString m_lastUrl;
    QString m_lastError;
};

#endif // IMAGEUPLOADER_H